﻿#pragma once
// #pragma comment(lib,"libmysql.lib")
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <string>

#include <mysql.h>
#include <errmsg.h>

using namespace std;

struct ConnInfo
{
    string hostname;
    unsigned int Port;

    string username;
    string passwd;

    string dbname;
};

class MySqlApi
{
public:
    MySqlApi(string ip, unsigned int port, string db, string user, string passwd);

    string GetMySqlError();

    bool ExecuteSql(string strsql);

    bool ExecuteSql(const char *sql, int length);

    bool ExecuteSql(vector<string> sqlvec);

    bool SelectSql(string sql, vector<map<string, string>> &Record);

    bool ConnDB();

    int IsClose();

public:
    ~MySqlApi(void);

private:
    struct ConnInfo conninfo;
    MYSQL mysql;

    bool IsConnect;
    string m_strError;
};
